import axios from 'axios';

// create an axios instance
const instance = axios.create({
  baseURL: process.env.BASE_API, // api的base_url
  timeout: 5000, // request timeout
});

// request interceptor
instance.interceptors.request.use(
  (config) => {
    // Do something before request is sent
    if (store.getters.token) {
      config.headers['X-Token'] = getToken();
    }
    return config;
  },
  (error) => {
    // Do something with request error
    console.log(error); // for debug
    Promise.reject(error);
  }
);

// respone interceptor
instance.interceptors.response.use(
  (response) => response,
  (error) => {
    console.log('err' + error); // for debug
    return Promise.reject(error);
  }
);

export default instance;
